package com.hyjx.framework.component.mutidatasource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.stereotype.Component;

/**
 * 动态数据源
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    public static final String DATASOURCE = "dataSourceS";
    public static final String DATASOURCEINTERFACE = "ds_1";
    
    public static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
    
    public static void setCustomerType(String customerType) {
        contextHolder.set(customerType);
    }
    
    public static String getCustomerType() {
        return contextHolder.get();
    }
    
    public static void clearCustomerType() {
        contextHolder.remove();
    }
    
    @Override
    protected Object determineCurrentLookupKey() {
        // TODO Auto-generated method stub
        return getCustomerType();
    }
}